package person.zjh.kaoyansharehub.controller;

import io.jsonwebtoken.Claims;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import person.zjh.kaoyansharehub.dto.UserLoginDTO;
import person.zjh.kaoyansharehub.dto.UserRegisterDTO;
import person.zjh.kaoyansharehub.result.Result;
import person.zjh.kaoyansharehub.service.UserService;
import person.zjh.kaoyansharehub.utils.JwtUtil;


/**
 * @description: 用户控制类
 * @author 郑佳豪
 * @date 2025/2/12 10:49
 * @version 1.0
 */
@RestController
@RequestMapping("/front/user")
@RequiredArgsConstructor
@Slf4j
public class UserController {

    private final UserService userService;

    @PostMapping("/userLogin")
    public Result userLogin(@RequestBody UserLoginDTO requestParam){
        log.info("用户登入参数：{}",requestParam);
        return userService.userLogin(requestParam);

    }


    @PostMapping("/userRegister")
    public Result<Void> userRegister(@RequestBody UserRegisterDTO requestParam){
        log.info("用户登入参数：{}",requestParam);
        userService.userRegister(requestParam);
        return Result.success();
    }

    @GetMapping("/getUserInfo")
    public Result<Object> getUserInfo(String token){
        Claims claims = JwtUtil.parseJWT(token);
        return Result.success(claims);
    }


}
